<template>
    <div>购买数量：
        <!-- <div class="mui-numbox" data-numbox-min='1' data-numbox-max='9'> -->
        <div class="mui-numbox" data-numbox-min='1' :data-numbox-max='max'>
            <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
            <input id="test" class="mui-input-numbox" type="number" value="1" @change="change" ref="numBox"/>
            <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
        </div>
    </div>
</template>

<script>
// 导入mui，初始化数字框
import mui from '../../../lib/mui/js/mui.js'

export default {
    props:['max'],
    data:function(){
        return {}
    },
    mounted:function(){
        mui('.mui-numbox').numbox();
    },
    methods:{
        change:function(){
            // 当数量变化，获取其当前数量
            // var currentNum = this.$refs.numBox.value;
            var currentNum = mui('.mui-numbox').numbox().getValue();
            // 触发事件向父组件传值
            this.$emit('numTrans',parseInt(currentNum));
        }
    },
    watch:{
        max:function(newval){
            // this.max=newval;
            mui('.mui-numbox').numbox().setOption('max',newval);
        }
    }
}
</script>

<style lang="scss" scoped>

</style>